# BigData course project
# Serial version of training algorithm for SOM
# Utility class

import sys
import datetime

# main
debug = 0

def log(fmt, *args):
    sys.stdout.write(fmt % args)
    sys.stdout.flush()

def deb(fmt, *args):
    if debug:
        log(fmt, *args)

# dumps a list of vector into a file (one vector per line)
def dump_vector_list(desc, vlist, file):
    try:
        f = open(file, "w")
    except IOError:
        log("Could not create %s dumpfile %s\n", desc, file)
        sys.exit(4)
    for v in vlist:
        try:
            f.write(" ".join(map(lambda f: "%.6f" % f, v)))
            f.write("\n")
        except:
            log("Could not write vector %s to %s dumpfile %s\n", 
                v, desc, file)
            sys.exit(5)            
    f.close()    

# returns current time in milliseconds (unix style)
def get_currtime():
    start = datetime.datetime(1970, 1, 1)
    return int((datetime.datetime.utcnow() - start).total_seconds() * 1000) 
